package edu.mapi.aamas.behaviors;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import jade.core.messaging.TopicManagementHelper;
import jade.lang.acl.ACLMessage;
import edu.mapi.aamas.uav.UavAgent;

public class SendState extends TickerBehaviour {

	public SendState(Agent a, long period) {
		super(a, period);
	}
	
	protected void onTick() {
		
		//System.out.println("Tick!");
		if (myAgent instanceof UavAgent) {

			UavAgent agent = (UavAgent) myAgent;
			
			try {
				TopicManagementHelper helper = (TopicManagementHelper) myAgent.getHelper(TopicManagementHelper.SERVICE_NAME);
				AID stateTopic = helper.createTopic("worldstate");
				helper.register(stateTopic);
				ACLMessage message = new ACLMessage(ACLMessage.INFORM);				
				message.setContentObject(agent.getPhysicalState());
				message.addReceiver(stateTopic);
				agent.send(message);				
			}
			catch (Exception e) {
				e.printStackTrace();
			}			
		}	
	}
	
	public static void main(String[] args) {			
	}
}
